package map.DSU;

import java.util.Scanner;

public class redundancy {
    public static void main(String[] args) {
        String sb = "";
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        init(n);
        for (int i = 0; i < n; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            if (find(s) != find(t)){
                join(s, t);
            } else {
                sb = s + " " + t;
            }
        }
        System.out.println(sb);
    }
    private static int[] father;
    public static void init(int n){
        father = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            father[i] = i;
        }
    }
    public static int find(int u) {
        if (u == father[u]){
            return u;
        } else {
            return find(father[u]);
        }
    }
    public static void join(int u, int v) {
        u = find(u);
        v = find(v);
        if (u != v){
            father[v] = u;
        }
    }
}
